package main

func main() {
	height := []int{1, 8, 6, 2, 5, 4, 8, 3, 7}
	area := maxArea(height)
	println(area)
}

// 11. 盛最多水的容器
func maxArea(height []int) int {
	arrayLen := len(height)
	left, right := 0, arrayLen-1

	max := 0
	for left < right {
		leftHeight := height[left]
		rightHeight := height[right]

		minHeight := MinNum(leftHeight, rightHeight)
		max = MaxNum(max, minHeight*(right-left))

		// // 比较两侧谁更短，短的已经是面积极限，则越过
		if leftHeight < rightHeight {
			left++
		} else {
			right--
		}
	}
	return max
}

func MinNum(num1, num2 int) int {
	if num1 > num2 {
		return num2
	}
	return num1
}

func MaxNum(num1, num2 int) int {
	if num1 > num2 {
		return num1
	}
	return num2
}
